package net.sf.nlp.segment;

import net.sf.nlp.segment.util.StringUtility;

public class AtomicWord implements Cloneable
{
	private int index;
	private String atomicWord;
	private String aliasWord;
	private boolean chinese;
	private boolean number;
	
	public AtomicWord(int index, String atomicWord, boolean chinese)
	{
		this.index = index;
		this.atomicWord = atomicWord;
		this.chinese = chinese;
		
		determinateType();
	}
	
	public int getIndex() {
		return index;
	}

	public String getAtomicWord() 
	{
		return atomicWord;
	}

	public String getAliasWord() 
	{
		if (aliasWord != null)
			return aliasWord;
		
		return atomicWord;
	}

	public boolean isChinese() 
	{
		return chinese;
	}

	public boolean isNumber() {
		return number;
	}

	public void setNumber(boolean number) {
		this.number = number;
	}

	public void append(String word)
	{
		if (atomicWord == null)
			atomicWord = word;
		else
			atomicWord = atomicWord + word;
		
		determinateType();
	}
	
	public void determinateType()
	{
		if (atomicWord == null)
			return;
		
		if (!chinese)
		{
			if (StringUtility.isDigital(atomicWord))
			{
				number = true;
				aliasWord = StringUtility.UNKNOWN_NUM;
			}
		}
		
		if (StringUtility.isNumber(atomicWord))
		{
			number = true;
			aliasWord = StringUtility.UNKNOWN_NUM;
		}
	}
	
	public AtomicWord clone()
	{
		try 
		{
			return (AtomicWord) super.clone();
		} 
		catch (CloneNotSupportedException e) 
		{
			e.printStackTrace();
		}
		
		return null;
	}
}
